<?php


class NApplication extends NObject {


function &getInstance ($client,$config=array(),$prefix="N")
	
    // this implements the 'singleton' design pattern.

    {

    		static $instances;

		if (!isset( $instances )) {
			$instances = array();
		}

		if (empty($instances[$client]))
		{
			//Load the router object
			
				$info =& new stdClass;
			$path = $info->path = $config->root_dir."/include/application.php";
			
			if(file_exists($path))
			{
				require_once $path;

				// Create a JRouter object
				$classname = $prefix.ucfirst($client);
				$instance = new $classname($config);
			}
			else
			{
				$error = NError::raiseError(500, 'Unable to load application: '.$client);
				return $error;
			}

			$instances[$client] =& $instance;
		}

		return $instances[$client];

        

    } // getInstance

function __construct($config){
$this->config=$config;
}
function dispatch(){}
function initialize(){
ob_start();
}
function render(){

$document = NFactory::createDocument($this->config);

$content = ob_get_contents();
ob_clean();
$data =  $document->render($content);

 NResponse::setBody($data);



}

function login($credential){
	require_once(FRAMEWORK_DIR."/libraries/neocasta/user/authentication.php");
	return  NAuthentication::authenticate($credential);
}

function redirect($url="",$msg="",$time="3"){
$theme=NFactory::getTheme();
	$theme->module_header.= "<meta http-equiv=\"Refresh\" content=\"$time; URL=$url\"> ";
?>
	
<div class=info><?=$msg?></div>
<div>Если вы не перешли на другую страницу через <b><?=$time?></b> сек. автоматически, то нажмите <a href="<?=$url?>">здесь</a></div>

	
<?php



}

function close( $code = 0 ) {
		exit($code);
	}


}
?>